#include "view_relax.h"
#include "display_ctrl.h"
#include "platform_assert.h"
#include "lfs_file_manager_auto.h"
#include "rtc.h"
#include "datetime.h"
#include "blecom.h"
#include "battery_ctrl.h"
#include "sport_his.h"
#include "display_ctrl.h"
#include "display_interface_240x240.h"
#include "datetime.h"
#include "heart_rate_interface.h"
#include "font/num_font.h"
#include "view_common.h"
#include "arm_math.h"
#include "lfs_file_manager.h"
#include "app_trace.h"
#include "app_timer.h"
#include "Motor.h"
#include "view_relax.inc"
#include "language_text.h"
#include "stopwatch.h"
#define LOG(fmt, ...)              // app_trace_log(fmt "\r\n", ##__VA_ARGS__)
#define BREATH_INTERVAL_SECOND (4) //!< 呼吸用的时间
int relax_animation_text_index(void)
{
    // 最小() 到最大  吸气
    // 最大到最小 呼气
    // FILE_IMG_3102_exhale 呼气
    // FILE_IMG_3107_breath_inhale 吸气
    uint32_t const time = stopwatch_get_catch_time(0);
    if (time % (BREATH_INTERVAL_SECOND * 2 * 1000) < BREATH_INTERVAL_SECOND * 1000)
    {
        return FILE_IMG_3102_exhale;
    }
    else
    {
        return FILE_IMG_3107_breath_inhale;
    }
}
uint8_t const *relax_animation_frame(void)
{
    uint32_t const time = stopwatch_get_catch_time(0);
    int const index = time % (BREATH_INTERVAL_SECOND * 2 * 1000);
    int animation_frame = 0; //!< 动画帧数，总是计算从小到大
    if (index < BREATH_INTERVAL_SECOND * 1000)
    {
        animation_frame = index;
    }
    else
    {
        animation_frame = BREATH_INTERVAL_SECOND * 2 * 1000 - index;
    }

    uint32_t const frame_total = sizeof(relax_animation_TAB) / sizeof(relax_animation_TAB[0]);
    int frame_index = frame_total * animation_frame / (BREATH_INTERVAL_SECOND * 1000) - 1;
    if (frame_index < 0)
    {
        return 0;
    }
    uint8_t const *bmp = relax_animation_TAB[frame_index];
    LOG("frame %d", frame_index);
    return bmp;
}
void view_relax_base_display(void)
{
#ifdef CUSTOM_UI
    int const temp_index_start = 50;
    int custom_ui_index = 0;

    for (int i = 0; i < RELAX_BACK_COUNT; i++)
    {
        disp_show_resource_with_x_y(DISP_LFS_FILE_INDEX_0 + custom_ui_index, localize_resource_key_relax_back_start + i, temp_index_start + custom_ui_index, -1, -1);
        ++custom_ui_index;
    }
#if RELAX_GIF_COUNT > 0
    disp_show_resource_with_x_y(DISP_LFS_FILE_INDEX_0 + custom_ui_index, localize_resource_key_relax_gif_start + disp_ctrl.auto_refresh_count % HEART_RATE_GIF_COUNT,
                                temp_index_start + custom_ui_index, -1, -1);
    ++custom_ui_index;
#endif
    int x = 76;
    int y = 177;
    if (disp_ctrl.com_data.uint8_temp[100])
    {
        y -= 3;
        disp_show_font_string_utf8_mid(y, (char const *)(&disp_ctrl.com_data.uint8_temp[101]), 0);
    }
    else
    {
        _disp_show_flash_img(DISP_LFS_FILE_INDEX_0 + custom_ui_index, x, y, FILE_IMG_3002_main_text);
    }
    //    bool ret = disp_show_localize(DISP_LFS_FILE_INDEX_0 + custom_ui_index, localize_string_key_relax_text, temp_index_start + custom_ui_index);
    // if (!ret)
    // {
    //     _disp_show_flash_img(DISP_LFS_FILE_INDEX_0 + custom_ui_index, 76, 177, FILE_IMG_3002_main_text);
    // }
    ++custom_ui_index;
#else
    int x = 61;
    int y = 42;
    _disp_show_flash_img(DISP_LFS_FILE_INDEX_0, x, y, FILE_IMG_3001_main_breathe);
    x = 76;
    y = 177;
    if (disp_ctrl.com_data.uint8_temp[100])
    {
        y -= 3;
        disp_show_font_string_utf8_mid(y, (char const *)(&disp_ctrl.com_data.uint8_temp[101]), 0);
    }
    else
    {
        _disp_show_flash_img(DISP_LFS_FILE_INDEX_1, x, y, FILE_IMG_3002_main_text);
    }
    show_button_up();
    show_button_right();
    show_button_down();
#endif
}
void view_relax_home_display(void)
{
    int x = 70;
    int y = 72;
    if (disp_ctrl.com_data.uint8_temp[50])
    {
        y += 1;
        disp_show_font_string_utf8_mid(y, (char const *)(&disp_ctrl.com_data.uint8_temp[51]), 0);
    }
    else
    {
        _disp_show_flash_img(DISP_LFS_FILE_INDEX_0, x, y, FILE_IMG_3103_breath_relax);
    }
    x = 28;
    y = 137;
    if (disp_ctrl.com_data.i_temp[0] == relax_option_time_5_min)
    {
        if (disp_ctrl.com_data.uint8_temp[100])
        {
            // 17 206
            // y += 1;
            x = 17;
            y -= 2;
            int x2 = 17 + 206;
            int y2 = y + 48;
            disp_show_font_string_utf8_area(x, y, x2, y2, (char const *)(&disp_ctrl.com_data.uint8_temp[101]), 0);
        }
        else
        {
            _disp_show_flash_img(DISP_LFS_FILE_INDEX_1, x, y, FILE_IMG_3104_breath_start_five);
        }
    }
    else
    {
        if (disp_ctrl.com_data.uint8_temp[150])
        {
            x = 17;
            y -= 2;
            int x2 = 17 + 206;
            int y2 = y + 48;
            disp_show_font_string_utf8_area(x, y, x2, y2, (char const *)(&disp_ctrl.com_data.uint8_temp[151]), 0);
        }
        else
        {
            _disp_show_flash_img(DISP_LFS_FILE_INDEX_1, x, y, FILE_IMG_3105_breath_start_two);
        }
    }
    x = 85;
    y = 207;
    // 200
    if (disp_ctrl.com_data.uint8_temp[200])
    {
        y -= 3;
        disp_show_font_string_utf8_mid(y, (char const *)(&disp_ctrl.com_data.uint8_temp[201]), 0);
    }
    else
    {
        _disp_show_flash_img(DISP_LFS_FILE_INDEX_2, x, y, FILE_IMG_3203_options);
    }
    show_button_right();
    x = 173;
    y = 210;
    disp_draw_user_image_ignore_color(x, y, RGB565_COLOR_BLACK, bmp_I200_btn_start);
}
void view_relax_tips_display(void)
{
    if (disp_ctrl.loop_cnt == 0)
    {
        disp_ctrl.auto_refresh_time = 1000;
        disp_ctrl.auto_close_delay = 2000;
        if (disp_ctrl.auto_refresh_count > 3)
        {
            display_show(view_relax_animation, DISP_MODE_NORMAL);
            return;
        }
    }
    int x = 0;
    int y = 0;
    if (disp_ctrl.com_data.uint8_temp[100])
    {
        // 19 56 201 130
        // y -= 4;
        // disp_show_font_string_utf8_mid(y, (char const *)(&disp_ctrl.com_data.uint8_temp[101]), 0);
        disp_show_font_string_utf8_area(19, 56, 19 + 201, 56 + 130, (char const *)(&disp_ctrl.com_data.uint8_temp[101]), 0);
    }
    else
    {
        _disp_show_flash_img(DISP_LFS_FILE_INDEX_0, x, y, FILE_IMG_view_relax_tips);
    }
}
void view_relax_option_time_display(void)
{
    int x = 85;
    int y = 28;
    if (disp_ctrl.com_data.uint8_temp[50])
    {
        y -= 3;
        disp_show_font_string_utf8_mid(y, (char const *)(&disp_ctrl.com_data.uint8_temp[51]), 0);
    }
    else
    {
        _disp_show_flash_img(DISP_LFS_FILE_INDEX_0, x, y, FILE_IMG_3203_options);
    }

    y = 94;
    y = 94 + 48;
    for (int i = 0; i < 240; i++)
    {
        disp_draw_point(i, 94, 0x528a);
        disp_draw_point(i, 94 + 48, 0x528a);
    }
    int first_index = 0;
    int second_index = 0;
    char const *first_text_str = 0;
    char const *second_text_str = 0;
    if (disp_ctrl.com_data.i_temp[0])
    {
        first_index = FILE_IMG_3204_practice_time;
        second_index = FILE_IMG_3205_shock;
        if (disp_ctrl.com_data.uint8_temp[100])
        {
            second_text_str = (char const *)&disp_ctrl.com_data.uint8_temp[101];
        }
        if (disp_ctrl.com_data.uint8_temp[150])
        {
            first_text_str = (char const *)&disp_ctrl.com_data.uint8_temp[151];
        }
    }
    else
    {
        first_index = FILE_IMG_3205_shock;
        second_index = FILE_IMG_3204_practice_time;
        if (disp_ctrl.com_data.uint8_temp[100])
        {
            first_text_str = (char const *)&disp_ctrl.com_data.uint8_temp[101];
        }
        if (disp_ctrl.com_data.uint8_temp[150])
        {
            second_text_str = (char const *)&disp_ctrl.com_data.uint8_temp[151];
        }
    }
    x = 30;
    y = 110;
    //-=5
    if (first_text_str)
    {
        disp_show_font_string_utf8_area(x, y, 214, y + 24, first_text_str, 0);
    }
    else
    {
        _disp_show_flash_img(DISP_LFS_FILE_INDEX_1, x, y, first_index);
    }

    x = 37;
    y = 168;
    if (second_text_str)
    {
        disp_show_font_string_utf8_area(x, y, 214, y + 24, second_text_str, 0);
    }
    else
    {
        _disp_show_flash_img(DISP_LFS_FILE_INDEX_2, x, y, second_index);
    }
    show_button_right();
}
void view_relax_option_shock_display(void)
{
    int x = 85;
    int y = 31;
    if (disp_ctrl.com_data.uint8_temp[100])
    {
        y -= 3;
        disp_show_font_string_utf8_mid(y, (char const *)(&disp_ctrl.com_data.uint8_temp[101]), 0);
    }
    else
    {
        _disp_show_flash_img(DISP_LFS_FILE_INDEX_0, x, y, FILE_IMG_3203_options);
    }
    x = 37;
    y = 108;
    if (disp_ctrl.com_data.uint8_temp[150])
    {
        y -= 5;
        disp_show_font_string_utf8_area(37, y, 168, y + 24, (char const *)(&disp_ctrl.com_data.uint8_temp[151]), 0);
    }
    else
    {
        _disp_show_flash_img(DISP_LFS_FILE_INDEX_1, x, y, FILE_IMG_3205_shock);
    }

    for (int i = 0; i < 240; i++)
    {
        disp_draw_point(i, 91, 0x528a);
        disp_draw_point(i, 138, 0x528a);
    }

    x = 178;
    y = 102;
    int option_index = 0;

    if (disp_ctrl.com_data.i_temp[0] == relax_option_shock_true)
    {
        option_index = FILE_IMG_3401_relax_on_178_102;
    }
    else
    {
        option_index = FILE_IMG_3402_relax_off_178_102;
    }
    _disp_show_flash_img(DISP_LFS_FILE_INDEX_2, x, y, option_index);
}
void view_relax_animation_end_display(void)
{
    if (disp_ctrl.loop_cnt == 0)
    {
        disp_ctrl.auto_refresh_time = 1000;
        disp_ctrl.auto_close_delay = 2000;
        if (disp_ctrl.auto_refresh_count > 5)
        {
            display_show(view_relax_home, DISP_MODE_NORMAL);
            return;
        }
    }
    int x = 0;
    int y = 0;
    _disp_show_flash_img(DISP_LFS_FILE_INDEX_0, x, y, FILE_IMG_3207_breathend);
    x += 42;
    y += 76;
    if (disp_ctrl.com_data.uint8_temp[100] && disp_ctrl.com_data.uint8_temp[150])
    {
        // y -= 3;
        // disp_show_font_string_utf8_area(y, (char const *)(&disp_ctrl.com_data.uint8_temp[101]), 0);
        disp_show_font_string_utf8_area(19, 56, 19 + 201, 56 + 77, (char const *)(&disp_ctrl.com_data.uint8_temp[101]), 0);
        disp_show_font_string_utf8_area(19, 56 + 77, 201, 56 + 77 + 53, (char const *)(&disp_ctrl.com_data.uint8_temp[151]), 0);
    }
    else
    {
        _disp_show_flash_img(DISP_LFS_FILE_INDEX_1, x, y, FILE_IMG_3207_breathend_42_76);
    }
}
void view_relax_animation_display(void)
{
    if (disp_ctrl.loop_cnt == 0)
    {
        disp_ctrl.auto_close_delay = 2000;
        uint32_t max_time = 0;
        if (disp_ctrl.com_data.i_temp[0] == relax_option_time_2_min)
        {
            max_time = 2 * 60 * 1000;
        }
        else
        {
            max_time = 5 * 60 * 1000;
        }
        uint32_t const time = stopwatch_get_catch_time(0);
        if (time >= max_time)
        {
            motor_start(500);
            display_show(view_relax_animation_end, DISP_MODE_NORMAL);
            return;
        }
        disp_ctrl.com_data.i_temp[2] = relax_animation_text_index();
        if (disp_ctrl.com_data.i_temp[3] != disp_ctrl.com_data.i_temp[2])
        {
            if (get_relax_option_shock() == relax_option_shock_true)
            {
                motor_start(100);
            }
            disp_ctrl.area_update_flag = 0;
        }
        else
        {
            display_set_update_area(75, 51, 90, 90);
        }
        disp_ctrl.com_data.i_temp[3] = disp_ctrl.com_data.i_temp[2];
        disp_ctrl.com_data.p_temp[4] = (void *)relax_animation_frame();
        disp_ctrl.auto_refresh_time = 0;
    }
    int x = 75;
    int y = 51;
    if (disp_ctrl.com_data.p_temp[4] != 0)
    {
        disp_draw_user_image(x, y, disp_ctrl.com_data.p_temp[4]);
    }

    x = 75;
    y = 166;
    if (disp_ctrl.com_data.uint8_temp[100] && disp_ctrl.com_data.uint8_temp[150])
    {
        y -= 1;
        if (disp_ctrl.com_data.i_temp[3] == FILE_IMG_3102_exhale)
        {
            disp_show_font_string_utf8_mid(y, (char const *)(&disp_ctrl.com_data.uint8_temp[151]), 0);
        }
        else
        {
            disp_show_font_string_utf8_mid(y, (char const *)(&disp_ctrl.com_data.uint8_temp[101]), 0);
        }
    }
    else
    {
        _disp_show_flash_img(DISP_LFS_FILE_INDEX_0, x, y, disp_ctrl.com_data.i_temp[3]);
    }
    //!< 一共98张图，第一张 0 ，最后一张
    // 1 1.7  16 4 最后一张 45
    // 16张第一次出现0.24      最后一张 44.94
}
void view_relax_option_time_set_display(void)
{

    int x = 59;
    int y = 28;
    if (disp_ctrl.com_data.uint8_temp[50])
    {
        y -= 5;
        disp_show_font_string_utf8_mid(y, (char const *)(&disp_ctrl.com_data.uint8_temp[51]), 0);
    }
    else
    {
        _disp_show_flash_img(DISP_LFS_FILE_INDEX_0, x, y, FILE_IMG_3204_practice_time);
    }

    int first_index = 0;
    int second_index = 0;
    char const *first_text_str = 0;
    char const *second_text_str = 0;
    if (disp_ctrl.com_data.i_temp[0] == relax_option_time_2_min)
    {
        first_index = FILE_IMG_3201_2minutes;
        second_index = FILE_IMG_3202_5minutes;
        if (disp_ctrl.com_data.uint8_temp[100])
        {
            first_text_str = (char const *)&disp_ctrl.com_data.uint8_temp[101];
        }
        if (disp_ctrl.com_data.uint8_temp[150])
        {
            second_text_str = (char const *)&disp_ctrl.com_data.uint8_temp[151];
        }
    }
    else
    {
        first_index = FILE_IMG_3202_5minutes;
        second_index = FILE_IMG_3201_2minutes;
        if (disp_ctrl.com_data.uint8_temp[100])
        {
            second_text_str = (char const *)&disp_ctrl.com_data.uint8_temp[101];
        }
        if (disp_ctrl.com_data.uint8_temp[150])
        {
            first_text_str = (char const *)&disp_ctrl.com_data.uint8_temp[151];
        }
    }

    _disp_show_flash_img(DISP_LFS_FILE_INDEX_1, 49, 105 + 32, FILE_IMG_line_158_1);
    _disp_show_flash_img(DISP_LFS_FILE_INDEX_3, 49, 105 - 49 + 32, FILE_IMG_line_158_1);
    x = 71 - 3;
    y = 105;
    if (first_text_str)
    {
        y -= 2;
        disp_show_font_string_utf8_mid(y, first_text_str, 0);
    }
    else
    {
        _disp_show_flash_img(DISP_LFS_FILE_INDEX_4, x, y, first_index);
    }
    x = 71 - 3;
    y = 105 + 49;
    if (second_text_str)
    {
        y -= 2;
        disp_show_font_string_utf8_mid(y, second_text_str, 0);
    }
    else
    {
        _disp_show_flash_img(DISP_LFS_FILE_INDEX_2, x, y, second_index);
    }

    show_button_up();
    show_button_right();
    show_button_down();
}
int32_t view_relax_display(int32_t view)
{
    Expects(view >= view_relax);
    Expects(view < view_relax + VIEW_LEVEL_0_SUB_COUNT);
    switch (view)
    {
    case view_relax_base:
        view_relax_base_display();
        break;
    case view_relax_home:
        view_relax_home_display();
        break;
    case view_relax_tips:
        view_relax_tips_display();
        break;
    case view_relax_option_time:
        view_relax_option_time_display();
        break;
    case view_relax_option_shock:
        view_relax_option_shock_display();
        break;
    case view_relax_option_time_set:
        view_relax_option_time_set_display();
        break;
    case view_relax_animation:
        view_relax_animation_display();
        break;
    case view_relax_animation_end:
        view_relax_animation_end_display();
        break;
    default:
        break;
    }
    return 0;
}
view_event_result_t view_relax_event(int32_t view, event_param_t event)
{
    Expects(view >= view_relax);
    Expects(view < view_relax + VIEW_LEVEL_0_SUB_COUNT);
    switch (view)
    {
    case view_relax_animation_end:
        switch (event.event)
        {
        case event_view_entry:
        {
            uint8_t *buff = &disp_ctrl.com_data.uint8_temp[101];
            uint32_t buff_len = &disp_ctrl.com_data.uint8_temp[150] - buff;
            disp_ctrl.com_data.uint8_temp[100] = get_language_text(language_text_index_Good_job, buff, buff_len);
            buff = &disp_ctrl.com_data.uint8_temp[151];
            buff_len = disp_ctrl.com_data.uint8_temp + sizeof(disp_ctrl.com_data.uint8_temp) - buff;
            disp_ctrl.com_data.uint8_temp[150] = get_language_text(language_text_index_End_of_breathing, buff, buff_len);
            return view_event_result_handled;
        }
        }
        break;
    case view_relax_base:
        switch (event.event)
        {
        case event_view_entry:
        {
            uint8_t *buff = &disp_ctrl.com_data.uint8_temp[101];
            uint32_t buff_len = disp_ctrl.com_data.uint8_temp + sizeof(disp_ctrl.com_data.uint8_temp) - buff;
            disp_ctrl.com_data.uint8_temp[100] = get_language_text(language_text_index_Relax, buff, buff_len);
            return view_event_result_handled;
        }
        }
        break;
    case view_relax_home:
        switch (event.event)
        {
        case event_view_entry:
        {
            disp_ctrl.com_data.i_temp[0] = get_relax_option_time();
            uint8_t *buff = &disp_ctrl.com_data.uint8_temp[51];
            uint32_t buff_len = &disp_ctrl.com_data.uint8_temp[100] - buff;
            disp_ctrl.com_data.uint8_temp[50] = get_language_text(language_text_index_Relax, buff, buff_len);

            buff = &disp_ctrl.com_data.uint8_temp[101];
            buff_len = &disp_ctrl.com_data.uint8_temp[150] - buff;
            disp_ctrl.com_data.uint8_temp[100] = get_language_text(language_text_index_Start_five_minutes_of_breathing_course, buff, buff_len);

            buff = &disp_ctrl.com_data.uint8_temp[151];
            buff_len = &disp_ctrl.com_data.uint8_temp[200] - buff;
            disp_ctrl.com_data.uint8_temp[150] = get_language_text(language_text_index_Start_two_minutes_of_breathing_course, buff, buff_len);

            buff = &disp_ctrl.com_data.uint8_temp[201];
            buff_len = disp_ctrl.com_data.uint8_temp + sizeof(disp_ctrl.com_data.uint8_temp) - buff;
            disp_ctrl.com_data.uint8_temp[200] = get_language_text(language_text_index_Options, buff, buff_len);
            return view_event_result_handled;
        }
        case event_move_next_view:
            display_show(view_relax_option_time, DISP_MODE_NORMAL);
            return view_event_result_handled;
        case BUTTON_EVENT_TP_TAP:
            if (event.y <= 180)
            {
                display_show(view_relax_tips, DISP_MODE_NORMAL);
            }
            else
            {
                display_show(view_relax_option_time, DISP_MODE_NORMAL);
            }
            return view_event_result_handled;
        }
        break;
    case view_relax_tips:
        switch (event.event)
        {
        case event_view_entry:
        {
            uint8_t *buff = &disp_ctrl.com_data.uint8_temp[101];
            uint32_t buff_len = disp_ctrl.com_data.uint8_temp + sizeof(disp_ctrl.com_data.uint8_temp) - buff;
            disp_ctrl.com_data.uint8_temp[100] = get_language_text(language_text_index_Quiet_and_take_a_deep_breath__, buff, buff_len);
            return view_event_result_handled;
        }
        case event_move_previous_view:
            return view_event_result_handled;
        case event_move_next_view:
            return view_event_result_handled;
        case BUTTON_EVENT_TP_TAP:
        case event_move_level_down:
            display_show(view_relax_animation, DISP_MODE_NORMAL);
            return view_event_result_handled;
        }
        break;
    case view_relax_option_time:
        switch (event.event)
        {
        case event_view_entry:
        {
            uint8_t *buff = &disp_ctrl.com_data.uint8_temp[51];
            uint32_t buff_len = &disp_ctrl.com_data.uint8_temp[100] - buff;
            disp_ctrl.com_data.uint8_temp[50] = get_language_text(language_text_index_Options, buff, buff_len);

            buff = &disp_ctrl.com_data.uint8_temp[101];
            buff_len = &disp_ctrl.com_data.uint8_temp[150] - buff;
            disp_ctrl.com_data.uint8_temp[100] = get_language_text(language_text_index_Shock, buff, buff_len);

            buff = &disp_ctrl.com_data.uint8_temp[151];
            buff_len = disp_ctrl.com_data.uint8_temp + sizeof(disp_ctrl.com_data.uint8_temp) - buff;
            disp_ctrl.com_data.uint8_temp[150] = get_language_text(language_text_index_Practice_time, buff, buff_len);

            return view_event_result_handled;
        }
        case event_move_previous_view:
        case event_move_next_view:
            disp_ctrl.com_data.i_temp[0] = !disp_ctrl.com_data.i_temp[0];
            display_set_update_request(view_relax_option_time, 0);
            return view_event_result_handled;
        case event_move_level_up:
            display_show(view_relax_home, DISP_MODE_NORMAL);
            return view_event_result_handled;
        case event_move_level_down:
            if (disp_ctrl.com_data.i_temp[0])
            {
                display_show(view_relax_option_time_set, DISP_MODE_NORMAL);
            }
            else
            {
                display_show(view_relax_option_shock, DISP_MODE_NORMAL);
            }
            return view_event_result_handled;
        }
        break;
    case view_relax_option_shock:
        switch (event.event)
        {
        case event_view_entry:
        {
            disp_ctrl.com_data.i_temp[0] = get_relax_option_shock();
            uint8_t *buff = &disp_ctrl.com_data.uint8_temp[101];
            uint32_t buff_len = &disp_ctrl.com_data.uint8_temp[150] - buff;
            disp_ctrl.com_data.uint8_temp[100] = get_language_text(language_text_index_Options, buff, buff_len);

            buff = &disp_ctrl.com_data.uint8_temp[151];
            buff_len = disp_ctrl.com_data.uint8_temp + sizeof(disp_ctrl.com_data.uint8_temp) - buff;
            disp_ctrl.com_data.uint8_temp[150] = get_language_text(language_text_index_Shock, buff, buff_len);

            return view_event_result_handled;
        }
        case event_move_previous_view:
        case event_move_next_view:
            return view_event_result_handled;
        case event_move_level_down:
            disp_ctrl.com_data.i_temp[0] = !disp_ctrl.com_data.i_temp[0];
            display_set_update_request(view_relax_option_shock, 0);
            set_relax_option_shock((relax_option_shock_t)disp_ctrl.com_data.i_temp[0]);
            return view_event_result_handled;
        }
        break;
    case view_relax_option_time_set:
        switch (event.event)
        {
        case event_view_entry:
        {
            disp_ctrl.com_data.i_temp[0] = get_relax_option_time();
            uint8_t *buff = &disp_ctrl.com_data.uint8_temp[51];
            uint32_t buff_len = &disp_ctrl.com_data.uint8_temp[100] - buff;
            disp_ctrl.com_data.uint8_temp[50] = get_language_text(language_text_index_Practice_time, buff, buff_len);

            buff = &disp_ctrl.com_data.uint8_temp[101];
            buff_len = &disp_ctrl.com_data.uint8_temp[150] - buff;
            disp_ctrl.com_data.uint8_temp[100] = get_language_text(language_text_index_2_minutes, buff, buff_len);

            buff = &disp_ctrl.com_data.uint8_temp[151];
            buff_len = disp_ctrl.com_data.uint8_temp + sizeof(disp_ctrl.com_data.uint8_temp) - buff;
            disp_ctrl.com_data.uint8_temp[150] = get_language_text(language_text_index_5_minutes, buff, buff_len);

            return view_event_result_handled;
        }
        case event_move_previous_view:
        case event_move_next_view:
            // 2，5分钟切换
            if (disp_ctrl.com_data.i_temp[0] == relax_option_time_2_min)
            {
                disp_ctrl.com_data.i_temp[0] = relax_option_time_5_min;
            }
            else if (disp_ctrl.com_data.i_temp[0] == relax_option_time_5_min)
            {
                disp_ctrl.com_data.i_temp[0] = relax_option_time_2_min;
            }
            display_set_update_request(view_relax_option_time_set, 0);
            return view_event_result_handled;
        case event_move_level_down:
            //! set ok
            set_relax_option_time((relax_option_time_t)disp_ctrl.com_data.i_temp[0]);
            display_show(view_relax_home, DISP_MODE_NORMAL);
            return view_event_result_handled;
        }
        break;
    case view_relax_animation:
        switch (event.event)
        {
        case event_move_previous_view:
            return view_event_result_handled;
        case event_move_next_view:
            return view_event_result_handled;
        case event_move_level_down:
            return view_event_result_handled;
        case event_view_entry:
        {
            stopwatch_start();
            disp_ctrl.com_data.i_temp[0] = get_relax_option_time();

            uint8_t *buff = &disp_ctrl.com_data.uint8_temp[101];
            uint32_t buff_len = &disp_ctrl.com_data.uint8_temp[150] - buff;
            disp_ctrl.com_data.uint8_temp[100] = get_language_text(language_text_index_Exhale, buff, buff_len);

            buff = &disp_ctrl.com_data.uint8_temp[151];
            buff_len = disp_ctrl.com_data.uint8_temp + sizeof(disp_ctrl.com_data.uint8_temp) - buff;
            disp_ctrl.com_data.uint8_temp[150] = get_language_text(language_text_index_Inhale, buff, buff_len);

            return view_event_result_handled;
        }
        case event_view_exit:
        {
            stopwatch_stop();
            return view_event_result_handled;
        }
        }
        break;
    }
    return view_event_result_not_handled;
}
// void view_relax_init(void)
// {
//     uint32_t err_code = app_timer_create(&relax_animation_timer, APP_TIMER_MODE_REPEATED, relax_animation_timer_handler);
//     if (err_code != NRF_SUCCESS)
//     {
//         LOG("relax creat timer fail[%u]", err_code);
//     }
// }
